/**
 * Description:
 * Class Name:conditionTest
 * Date:2022/5/8 14:19
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第16章_多线程._16_6_线程间通信._16_6_2_使用Condition控制线程来通信;

public class conditionTest {
    private static class drawThread extends Thread{
        private conditionAccount account;
        private double drawAmount;
        public drawThread(){}
        public drawThread(String name, conditionAccount account, double drawAmount){
            super(name);
            this.account = account;
            this.drawAmount = drawAmount;
        }

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                account.draw(drawAmount);
            }
        }
    }

    private static class depositThread extends Thread{
        private conditionAccount account;
        private double depositAmount;
        public depositThread(){}
        public depositThread(String name, conditionAccount account, double depositAmount){
            super(name);
            this.account = account;
            this.depositAmount = depositAmount;
        }

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                account.deposit(depositAmount);
            }
        }
    }

    public static void main(String[] args) {
        var user = new conditionAccount("1234567", 1000);
        new drawThread("取钱者甲", user, 800).start();
        new depositThread("存钱者乙", user, 800).start();
    }
}
